# -*- coding: utf-8 -*-
import traceback
from common.utils import Utils
from config.config import Config
from common.page import Page


class ServiceUtils:

    def initial_service_sql(self, client_id, businflow_no):
        if Config().env == 'test':
            Utils.search_for_param('mysql', 'sql/service_sql.json', 'initial_service_sql', ['1', client_id, businflow_no], '作废网厅新中台业务流水成功。')
        else:
            assert True

    def initial_bop_sql(self, client_id, acpt_busin_kind):

        if Config().env == 'test':
            Utils.search_for_param('bop', 'sql/service_sql.json', 'initial_bop_sql', ['8', client_id, acpt_busin_kind], '作废BOP业务流水成功。')
        else:
            assert True

    @staticmethod
    def assert_element(els, is_els=False, num=None, log=None):
        """

        @param is_els: 页面是否有多个相同元素
        @param num: 元素下标
        @param els:页面元素信息:el[0],el[1],el[2],需要断言的信息:el[3]，断言报错信息:el[4]
        @param log:日志信息
        @return:
        """
        Page.check_page_loading(3)
        if not is_els:
            for el in els:
                if len(el) == 5:
                    assert Page.element(el[0], el[1], el[2]).text == el[3], el[4]
                if len(el) == 4:
                    assert Page.element(el[0], el[1], el[2]).text == el[3]
        if is_els:
            for el in els:
                for i in num:
                    if len(el) == 5:
                        assert Page.elements(el[0], el[1], el[2])[i].text == el[3], el[4]
                    if len(el) == 4:
                        assert Page.elements(el[0], el[1], el[2])[i].text == el[3]
        s = traceback.extract_stack()
        m = {'appname': s[-2].filename.split('\\')[-1] + f' line in {s[-2].lineno}'}
        Page.logger.info(log, extra=m)

